package com.palominocia.capa_datos_nodoCentral.dbPostgreSQL.schema1.servicios.seguridad;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import org.apache.ws.security.WSPasswordCallback;

import com.palominocia.capa_datos_nodoCentral.dbPostgreSQL.schema1.modelo.seguridad.Usuario;

public class PasswordCallback  implements CallbackHandler {

	   public void handle(Callback[] callbacks) throws IOException,
	         UnsupportedCallbackException {
		  System.out.println("*******");
	      WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
	      
	      Usuario user =Usuario.findNombreUsuario(pc.getIdentifier());
	      if(user instanceof Usuario){
	    	  System.out.println("** pc.getIdentifier() "+pc.getIdentifier());
		      System.out.println("** pc.getPassword() "+pc.getPassword());
		      if(user.getUsername().equals(pc.getIdentifier())){
		    	// set the password on the callback. This will be compared to the
			    // password which was sent from the client.
		    	  pc.setPassword(user.getPassword());
		      }
	      }
	      
	   }
	}
